package com.suntianci.stock.config;

import com.suntianci.stock.pojo.vo.StockInfoConfig;
import com.suntianci.stock.utils.IdWorker;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @ClassName CommonConfig
 * @Author 孙天赐
 * @Date 2024/12/25 10:37
 * @Description TODO: 公共配置类
 */
@Configuration
@EnableConfigurationProperties({StockInfoConfig.class})  // 开启配置类 StockInfoConfig.class
public class CommonConfig {
    /**
     * 定义密码加密、匹配器
     * BCryptPasswordEncoder方法采用SHA-256对密码进行加密
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    /**
     * TODO: 基于雪花算法，保证分布式情况下生成的ID唯一
     * 参数1：机器ID
     * 参数2：机房ID
     * @return
     */
    @Bean
    public IdWorker idWorker(){
        //基于运维人员对机房和机器的编号规划自行约定
        return new IdWorker(1l,2l);
    }

//    /**
//     * 定义获取权限相关的工具类bean
//     * @return
//     */
//    @Bean
//    public PermissionUtil userPermissionUtil(){
//        return new PermissionUtil();
//    }
}